package com.ysten.basic.common.log.parser;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <SQL语段，暂时只处理update\delete语句>
 * 
 * @author 陆小凤
 * @version [版本号, 2014年9月22日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class HqlSegment
{
    private String start;
    
    private String body;
    
    private String segmentRegExp;
    
    public HqlSegment(String segmentRegExp)
    {
        this.start = "";
        this.body = "";
        this.segmentRegExp = segmentRegExp;
    }
    
    public void parse(String sourceSql)
    {
        Pattern pattern = Pattern.compile(segmentRegExp);
        Matcher matcher = pattern.matcher(sourceSql);
        
        if (matcher.find())
        {
            start = matcher.group(1);
            body = matcher.group(2);
        }
    }
    
    public String getStart()
    {
        return start;
    }
    
    public String getBody()
    {
        return body;
    }
    
    public String getCommnet()
    {
        return start + body;
    }
}